<?php
	
	require_once "Control\LoginController.php";
	require_once "Control\FileUploadController.php";
	require_once "Control\RegisterController.php";
	
	require_once "Model\Page.php";
	require_once "View\PageCompositionView.php";
	
	require_once "Common\DBConnection.php";
	
	class Mastercontroller{
		
		public function DoControll(){
			
			$db_connection = new DBConnection();
			
			$loginController = new LoginController();
			$fileuploadController = new FileUploadController();
			$registerController = new RegisterController();
			
			$page = new Page();
			$pageCompositionView = new PageCompositionView();
			
			//Kör de kontroller som finns.
			$loginOutput = $loginController->DoControll();
			$fileUploadOutput = $fileuploadController->DoControll($loginOutput->isLoggedIn);
			switch($loginOutput){
				//Kollar om användaren vill registrera sig...
				case $loginOutput->isSigningUp === TRUE:
					//...Och isf skrives registreringfformulär ut.
					$registerOutput = $registerController->DoControll();
					$page->m_title = $registerOutput->m_title;
					$page->m_javascript = $registerOutput->m_javascript;
					$content = $registerOutput->m_body;
					break;
				//...Eller inte...
				default:
					//Samlar ihop html-delarna till sidans kropp...
					$page->m_title = $loginOutput->m_title;
					$content = $loginOutput->m_body . $fileUploadOutput->m_body;
					
					break;
			}
			//...Och bygger ihop och returnerar kroppen.
			$page->m_body = $pageCompositionView->BuildPageBody($content);
			return $page;
		}
	}
?>